package com.ssh.tts.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.ssh.tts.model.Train;
import com.ssh.utils.DBConnection;

public class TrainDao {
	/**
	 * 根据车次查询
	 * @param train
	 * @return
	 */
	public List<Train> queryTrain(Train train){
		String sql = "select * from train where train_from = ? and train_to = ?";
		List<Object> list = new ArrayList<>();
		list.add(train.getTRAIN_FROM());
		list.add(train.getTRAIN_TO());
		if (!Objects.equals(train.getTRAIN_TRAINID(), "")) {
			sql += " and train_trainid = ?";
			list.add(train.getTRAIN_TRAINID());
		}
		if (!Objects.equals(train.getTRAIN_DATE(), "")) {
			sql += " and train_date = ?";
			list.add(train.getTRAIN_DATE());
		}
		return DBConnection.query(sql, Train.class, list.toArray());
	}
	/**
	 * 根据车号查询
	 * @param trainid
	 * @return
	 */
	public List<Train> queryTrainByTrainId(String trainid){
		String sql = "select * from train where train_trainId = ?";
		return DBConnection.query(sql, Train.class, trainid);
	}
	
}
